#include <vcl\vcl.h>
#pragma hdrstop

#include <EIC.h>
#include "uSelJnl.h"

#pragma package(smart_init)
#pragma link "CDBLkcb"
#pragma link "CDBGrid"
#pragma link "CTable"
#pragma link "CBitBtn"
#pragma resource "*.dfm"
#define MODULE_TAG 1003



__fastcall TdlgSelectJnl::TdlgSelectJnl(TTableJnx *ptblJnx,AnsiString *CodeJournal,bool VoirEIC,bool VoirReadOnly) : CForm()
{
  ASSERT(ptblJnx);
  ASSERT(ptblJnx->Active);
  ASSERT(!ptblJnx->Filtered);
  ASSERT(ptblJnx->OnFilterRecord == NULL);

  m_ptblJnx = ptblJnx;
  m_CodeJournal = CodeJournal;
  *m_CodeJournal = EmptyStr;
  m_VoirEIC = VoirEIC;
  m_VoirReadOnly = VoirReadOnly;
  dsJnx->DataSet = ptblJnx;
  ptblJnx->OnFilterRecord = FilterRecord;
  ptblJnx->Filtered = true;
  m_ptblJnx->First();
  DBGrid1->Columns->Items[0]->Width = 60;
}



void __fastcall TdlgSelectJnl::bSelectionnerClick(TObject *Sender)
{
  *m_CodeJournal = m_ptblJnx->FieldByName(TTableJnx::strfJN_Code)->AsString;
}



void __fastcall TdlgSelectJnl::FormClose(TObject *Sender,TCloseAction &Action)
{
  dsJnx->DataSet = NULL;
  m_ptblJnx->Filtered = false;
  m_ptblJnx->OnFilterRecord = NULL;
}



void __fastcall TdlgSelectJnl::FilterRecord(TDataSet *DataSet,bool &Accept)
{
  Accept = (!m_ptblJnx->EstEIC || m_VoirEIC) && (!m_ptblJnx->EstReadOnly || m_VoirReadOnly);
}



void __fastcall TdlgSelectJnl::bCreerClick(TObject *Sender)
{
  bool bExisteDeja;
  AnsiString Journal;
  TableJnx1->Open();
  if (TableJnx1->CreerDlg(TAGL,EmptyStr,bExisteDeja))
    Journal = TableJnx1Code->AsString;
  TableJnx1->Close();
  if (!Journal.IsEmpty())
    {
      m_ptblJnx->Refresh();
      m_ptblJnx->Locate(TTableJnx::strfJN_Code,Journal,TLocateOptions());
    }
}



